package gases.as3.librarys.compnents.ui.control.list
{
	import flash.display.BitmapData;
	import flash.text.TextField;
	
	import gases.as3.librarys.compnents.ui.GSkinBox;
	import gases.as3.librarys.compnents.ui.GUIComepments;
	import gases.as3.librarys.compnents.ui.basic.GLabel;
	
	public class ListCell extends GUIComepments
	{
		public static const INIT_HEIGHT:Number = 20;
		
		/**
		 *背景颜色初始值 
		 */		
		public static const BG_INIT_COLOR:uint = 0x03dcb1;
		/**
		 *鼠标移上去改变颜色 
		 */		
		public static const BG_OVER_COLOR:uint = 0xDD00DD;
		/**
		 *鼠标点击改变颜色 
		 */		
		public static const BG_CLICK_COLOR:uint = 0xFFDD00;
		
		public function ListCell(txt:String = "",bmd:BitmapData = null)
		{
			_txt = txt;
			_bmd = bmd;
			super();
		}
		
		override protected function initialization():void
		{
			super.initialization();
			_label = new GLabel("");
			_label.mouseEnabled = true;
			
			_icon = new GSkinBox();
			
			_txtBg = new TextField();
			
			_txtBg.borderColor = 0x000000;
			_txtBg.border = true;
			_txtBg.background = true;
			_txtBg.backgroundColor = BG_INIT_COLOR;
			
			updateUIPostion();
			this.addChild(_label);
			this.addChild(_icon);
			this.addChildAt(_txtBg,0);
		}
		
		override public function dispose():void
		{
			if(this.contains(_label))
			{
				this.removeChild(_label);
			}
			if(this.contains(_icon))
			{
				this.removeChild(_icon);
			}
			if(this.contains(_txtBg))
			{
				this.removeChild(_txtBg);
			}
			_label = null;
			_icon = null;
			_txtBg = null;
			super.dispose();
		}
		/**
		 *更新单元label 
		 * @param value
		 * 
		 */		
		public function updateCellLabel(value:String):void
		{
			_txt = value;
			updateUIPostion();
		}
		
		/**
		 *更新图标 
		 * @param bmd
		 * 
		 */		
		public function updateCellIcon(bmd:BitmapData):void
		{
			_bmd = bmd;
			updateUIPostion();
		}
		
		public function get Bmd():BitmapData
		{
			return _bmd;
		}
		
		public function get Txt():String
		{
			return _txt;
		}
		
		private function updateUIPostion():void
		{
			_label.text = _txt;
			if(_bmd)
			{
				_icon.source = 	_bmd;
				_icon.width =	_bmd.width;
				_icon.height = 	_bmd.height;
				_label.x = 		_bmd.width;
				_txtBg.x = 		_bmd.width;
			}
			else
			{
				_label.x = 0;
				_txtBg.x = 0;
			}
			_txtBg.width = 	_label.width;
			_txtBg.height =  _label.height;
		}
		
		public function cellOver():void
		{
			_txtBg.background = true;
			_txtBg.backgroundColor = BG_OVER_COLOR;
		}
		
		public function cellOut():void
		{
			_txtBg.background = true;
			_txtBg.backgroundColor = BG_INIT_COLOR;
		}
		
		public function cellClick():void
		{
			_txtBg.background = true;
			_txtBg.backgroundColor = BG_CLICK_COLOR;
		}
		
		private var _txt:String;
		private var _bmd:BitmapData;
		
		private var _label:GLabel;
		private var _icon:GSkinBox;
		
		
		private var _txtBg:TextField;
	}
}